/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2025 CCBlueX
 *
 * LiquidBounce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LiquidBounce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit.phase.modes

import net.ccbluex.liquidbounce.config.types.nesting.Choice
import net.ccbluex.liquidbounce.config.types.nesting.ChoiceConfigurable
import net.ccbluex.liquidbounce.event.events.BlockShapeEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.modules.exploit.phase.ModulePhase
import net.ccbluex.liquidbounce.utils.entity.withStrafe
import net.minecraft.block.FluidBlock
import net.minecraft.util.shape.VoxelShapes

/**
 * @anticheat UNCP + Verus + "Watchdog"
 * @anticheatVersion 14.07.2025
 * @testedOn blocksmc.com
 * @author liquidsquid1
 */
object PhaseBlocksMC : Choice("BlocksMC") {

    override val parent: ChoiceConfigurable<*>
        get() = ModulePhase.mode

    private var spiderTicks = 1

    override fun enable() {
        spiderTicks = 1
        player.velocity.y = 0.0
        super.enable()
    }

    @Suppress("unused")
    private val tickHandler = tickHandler {
        when (spiderTicks) {
            1 -> {
                if (mc.options.jumpKey.isPressed && !world.getBlockState(player.blockPos).isAir) {
                    player.velocity.y = 0.42
                    spiderTicks++
                }
                player.isOnGround = true
            }
            2 -> {
                player.velocity.y = 0.33
                spiderTicks++
            }
            3 -> {
                player.velocity.y = 0.25
                spiderTicks++
            }
        }

        if (spiderTicks > 3 || spiderTicks == 0) {
            spiderTicks = 1
        }
        player.noClip = true
        if (player.isSneaking) {
            player.velocity = player.velocity.withStrafe(speed = 0.179)
        }
    }

    @Suppress("unused")
    private val shapeHandler = handler<BlockShapeEvent> { event ->
        if (event.state.block is FluidBlock) {
            return@handler
        }

        if (event.pos.y >= player.y) {
            event.shape = VoxelShapes.empty()
        }
    }

}
